class_name HashMap

var nodes:Array = []

func put(key, value):
#	print("HashMap.put. key.x=", key.x, ",key.y=", key.y)
	var index = -1
	for i in range(nodes.size()):
		var node = nodes[i]
		if node.key==key || (node.key is BaseClass && node.key.equals(key)):
			index = i
			break
	if index >=0:
		nodes.remove(index)
	var node = HashNode.new()
	node.init(key, value)
	nodes.append(node)

func get(key):
#	print("HashMap.get.x=", key.x,",y=",key.y)
	for node in nodes:
		if node.key==key:
			return node.value
		if node.key is BaseClass && node.key.equals(key):
			return node.value
	return null

func contains(key)->bool:
	for node in nodes:
		if node.key==key:
			return true
		if node.key is BaseClass && node.key.equals(key):
			return true
	return false
	
func remove(key):
	print(nodes.size())
	for x in range(nodes.size()):
		var node = nodes[x]
		if node.key==key:
			nodes.remove(x)
			return
		if node.key is BaseClass && node.key.equals(key):
			nodes.remove(x)
			return

func size()->int:
	return nodes.size()

func clear():
	nodes = []
	
func keys()->ArrayList:
	var keys = ArrayList.new()
	for node in nodes:
		keys.add(node.key)
	return keys

func isEmpty()->bool:
	return nodes==null || nodes.size()<=0

